package Game;

import java.awt.*;
import java.util.ArrayList;

import Game.ManagerSound.Type;


public class RectManager
{
	public static ArrayList<RectArkanoid> recs;

	//ID = Cena Atual.
	public static void Setup(int quantColunas, int quantLinhas, int ID)
	{
		recs = new ArrayList<RectArkanoid>();
		
		for(int i = 0; i < quantLinhas; i++)
		{
			for(int j = 0; j < quantColunas; j++)
			{
				RectArkanoid temp = new RectArkanoid(j + 60 + (j * 45), 20 + i * 40 + i , 40, 30, ID);
				
				recs.add(temp);
			}
		}
	}	

	public static  void Update(ArkanoidBall ball)
	{
		for(int i = 0; i < recs.size(); i++)
		{
			recs.get(i).Update();
			
			//Mudar o parametro
			if(recs.get(i).Collision(ball))
			{
				if(ball.y + ball.h < recs.get(i).y + recs.get(i).h)
				{
					ball.speedx *= -1;
				}
				else
				{
					ball.speedy*= -1;
				}
				
				recs.remove(i);
				
				ManagerSound.getIntance().Play(Type.COLLISION);
			}
		}
	}
	
	public static void Draw(Graphics g)
	{
		for(int i = 0; i < recs.size(); i++)
		{
			recs.get(i).Draw(g);
		}
	}
}
